package com.yang.staff.controller;

import com.sun.javafx.tk.TKClipboard;
import com.yang.staff.pojo.Department;
import com.yang.staff.pojo.Staff;
import com.yang.staff.service.StaffService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

@CrossOrigin
@RestController
@RequestMapping("/staff")
public class StaffController {

    @Autowired
    private StaffService staffService;

    @PostMapping("/login")
    public Map<String, Object> login(@RequestBody Staff staff) {
        return staffService.login(staff);
    }

    @GetMapping("/decodingToken/{token}")
    public Staff decodingToken(@PathVariable String token) {
        return staffService.decodingToken(token);
    }

    @GetMapping("/friendList")
    public Map<String, Object> friendList(HttpServletRequest request) {
        String token = request.getHeader("token");
        // 校验token
        Staff staff = staffService.decodingToken(token);
        return staffService.friendList(staff);
    }

    @PostMapping("/register")
    public Boolean register(@RequestBody Staff staff) {
        return staffService.register(staff);
    }

    @GetMapping("/departments")
    public List<Department> departments() {
        return staffService.departments();
    }

    @GetMapping("/wordsProhibit")
    public List<Map> wordsProhibit() {
        return staffService.wordsProhibit();
    }
}
